<template>
  <div class="official">
    <div class="left">
      <div
        class="mark"
        :style="{
          backgroundImage: `url(${officialInfo.backgroundImage})`,
          backgroundSize: '100%'
        }"
      />
      <img :src="officialInfo.coverImgUrl" alt="">
      <div class="bofang"/>
      <i class="iconfont icon65zanting"/>
      <span class="update-time">{{officialInfo.updateTime}}更新</span>
    </div>
    <ul class="right">
      <li class="songItem" v-for="(song, index) of officialInfo.tk" @dblclick="selectSong(song.id)" :key="song">
        <div class="song-left">
          <span class="index" :class="{ 'top': index < 3 }">{{index + 1}}</span>
          -
          <p class="song-name-desc" :title="song.name + song.aliaStr">
            <span class="song-name">{{song.name}}</span>
            <span class="alias">{{song.aliaStr}}</span>
          </p>
        </div>
        <div class="song-right">
          <template v-for="(artist, len) of song.artists" :key="artist">
            <span class="artist" :title="artist.name" @click.stop="selectSinger(artist.id)">{{artist.name}}</span>
            <span v-if="len < song.artists.length - 1">/</span>
          </template>
        </div>
      </li>
      <li class="look-all">
        <div @click="selectPlaylist" class="box">
          <span>查看全部</span>
          <i class="iconfont iconyou"></i>
        </div>
      </li>
    </ul>
  </div>
</template>

<script lang="ts">
import { useRouter } from 'vue-router'
import { player } from '@/store/modules/player'

export default {
  name: 'Official',
  props: {
    officialInfo: {
      type: Object,
      default: () => ({})
    }
  },
  setup (props) {
    const router = useRouter()
    const selectSinger = (id) => {
      router.push({ name: 'singerDetail', params: { id } })
    }
    const selectPlaylist = () => {
      router.push({ name: 'playlistDetail', params: { id: props.officialInfo.id } })
    }
    const selectSong = (id) => {
      player.selectDanqu(id)
    }
    return {
      selectSinger,
      selectPlaylist,
      selectSong
    }
  }
}
</script>

<style lang="scss" scoped>
.official {
  display: flex;
  width: 100%;
  margin-bottom: 15px;

  .left {
    position: relative;
    height: 172px;
    width: 172px;
    border-radius: 5px;
    overflow: hidden;
    color: #ffffff;
    font-size: 12px;
    text-align: center;
    cursor: pointer;

    .mark {
      filter: blur(2px);
      width: 100%;
      height: 100%;
    }

    >img {
      position: absolute;
      top: 0;
      left: 0;
      width: 172px;
      height: 172px;
      border-radius: 5px;
      opacity: .9;
    }

    .bofang {
      display: none;
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      height: 35px;
      width: 35px;
      line-height: 35px;
      border-radius: 50%;
      opacity: .6;
      background-color: #fff;

      &:hover {
        display: block;
      }
    }

    >i {
      position: absolute;
      display: none;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      font-size: 20px;
      color: #ec4141;
    }

    &:hover {

      .bofang {
        display: block;
      }

      >i {
        display: inline-block;
      }
    }

    .update-time {
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translateX(-50%);
      margin-top: 25px;
    }
  }

  .right {
    flex: 1;
    padding-left: 20px;
    box-sizing: border-box;

    >li {
      height: 35px;
      font-size: 13px;
      border-radius: 3px;
      cursor: default;
    }

    >li:nth-of-type(odd) {
      background-color: #f4f4f4;
    }

    .songItem {
      display: flex;
      align-items: center;
      justify-content: space-between;
      color: #989898;
      line-height: 1.4;

      .song-left {
        flex: 1;
        display: flex;
        flex-wrap: nowrap;

        .index {
          padding-left: 5px;
          padding-right: 5px;
          font-weight: 600;
        }

        .top {
          color: #ec4141;
        }

        .song-name-desc {
          flex: 1;
          display: -webkit-box;
          -webkit-box-orient: vertical;
          -webkit-line-clamp: 1;
          overflow: hidden;
          padding-left: 5px;
          padding-right: 10px;

          .song-name {
            color: #333333;
            padding-right: 2px;
          }
        }
      }

      .song-right {
        display: flex;
        align-items: center;
        padding-right: 5px;

        .artist {
          cursor: pointer;
        }
      }

      &:hover {
        background-color: #ebebeb;
      }
    }

    .look-all {
      line-height: 35px;

      .box {
        display: flex;
        align-items: center;
        color: #989898;
        font-size: 12px;

        > i {
          font-size: 20px;
        }

        &:hover {
          color: #333333;
        }
      }
    }
  }
}
</style>
